package Jiemian;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.*;

import dao.Dao;

import staff.Article_loss_management;
import staff.Gr;
import staff.Healthfill;

public class Caidan1 extends JPanel implements ActionListener{
	private JButton b1,b2,b3;
	private JPanel p1,p2;
	private String room;
	public Caidan1(String room){
		p1=new JPanel();
		p1.setLayout(new GridLayout(9,1));
		p1.setOpaque(false);
		b1=new JButton("老人每日健康状况填写");
		b1.setBackground(new Color(0,150,250));
		b1.setForeground(Color.white);
		b1.setFont(new Font("微软雅黑",1,15));
		b2=new JButton("物品损耗状况");
		b2.setBackground(new Color(0,150,250));
		b2.setForeground(Color.white);
		b2.setFont(new Font("微软雅黑",1,15));
		b3=new JButton("个人信息管理");
		b3.setBackground(new Color(0,150,250));
		b3.setForeground(Color.white);
		b3.setFont(new Font("微软雅黑",1,15));
		p1.add(b1);
		p1.add(b2);
		p1.add(b3);
		this.setLayout(new BorderLayout());
		this.add(p1,"West");
		p2=new JPanel();
		p2.setLayout(new BorderLayout());
		p2.setOpaque(false);
		JScrollPane sr=new JScrollPane(p2);
		this.add(sr,"Center");
		this.setOpaque(false);
		this.room=room;
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource()==b1){
			p1.setVisible(false);
			p1.removeAll();
			b3.setBackground(new Color(0,150,250));
			b3.setForeground(Color.white);
			b2.setBackground(new Color(0,150,250));
			b2.setForeground(Color.white);
			b1.setBackground(Color.white);
			b1.setForeground(Color.black);
			p1.add(b1);
			p1.add(b2);
			p1.add(b3);
			p1.setVisible(true);
			p2.setVisible(false);
			p2.removeAll();
			p2.add(new Healthfill(room),"Center");
			p2.setVisible(true);
		}
		if(e.getSource()==b2){
			p1.setVisible(false);
			p1.removeAll();
			b2.setBackground(Color.white);
			b2.setForeground(Color.black);
			b1.setBackground(new Color(0,150,250));
			b1.setForeground(Color.white);
			b3.setBackground(new Color(0,150,250));
			b3.setForeground(Color.white);	
			p1.add(b1);
			p1.add(b2);
			p1.add(b3);
			p1.setVisible(true);
			p2.setVisible(false);
			p2.removeAll();
			p2.add(new Article_loss_management(room),"Center");
			p2.setVisible(true);
		}
		if(e.getSource()==b3){
			p1.setVisible(false);
			p1.removeAll();
			b1.setBackground(new Color(0,150,250));
			b1.setForeground(Color.white);
			b3.setBackground(Color.white);
			b3.setForeground(Color.black);
			b2.setBackground(new Color(0,150,250));
			b2.setForeground(Color.white);
			p1.add(b1);
			p1.add(b2);
			p1.add(b3);
			p1.setVisible(true);
			p2.setVisible(false);
			p2.removeAll();
			String sql="select * from staff where room='"+room+"'";	
			Dao d=new Dao();
		    String[][]a=d.doSelect(sql);
		    p2.add(new Gr(a[0][0],a[0][1],a[0][2],a[0][3], a[0][7], a[0][5], a[0][6], a[0][8], a[0][9], a[0][4]));
		    p2.setVisible(true);
		}
	}
}
